﻿using System;
using System.Collections.Generic;

namespace ConsoleDemo
{
    /// <summary>
    /// 迭代器
    /// </summary>
    internal class IteratorDemo
    {
        public static void IteratorTest()
        {
            MyClass myClass = new MyClass();
            foreach (string item in myClass)
            {
                Console.WriteLine(item);
            }
        }
    }

    internal class MyClass
    {
        public IEnumerator<string> BlackAndWhite()
        {
            yield return "1x";
            yield return "2z";
            yield return "3y";
        }

        public IEnumerator<string> GetEnumerator()
        {
            return BlackAndWhite();
        }
    }
}
